'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const {data:{access_token,openid,unionid}} = await uniCloud.httpclient.request('https://api.weixin.qq.com/sns/oauth2/access_token',
		{			
			method: 'GET',
			dataType:"json",
			data: {
				"appid":"wxd1f11eba5635d9d7",
				"secret":"b7e366fd46eb0bfc1ff4302de3969022",
				"grant_type":"authorization_code",
				"code":event.code //这个是前端传来的
			}
		});
	//返回数据给客户端
	return await uniCloud.httpclient.request(
		'https://api.weixin.qq.com/sns/userinfo',
		{			
			method: 'GET',
			dataType:"json",
			data: {
				access_token,openid,
				"lang":"zh_CN",
			}
		},
	);
	
	// return event
};
